<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="管辖区" prop="areaName">
        <el-select v-model="queryParams.areaName" placeholder="请选择管辖区" clearable size="small">
          <el-option
            v-for="dict in areaNameOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建开始时间" prop="createTimeBegin" label-width="100px">
        <el-date-picker clearable size="small"
                        v-model="queryParams.createTimeBegin"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择创建开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建结束时间" prop="createTimeEnd" label-width="100px">
        <el-date-picker clearable size="small"
                        v-model="queryParams.createTimeEnd"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择创建结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="shipList">
      <el-table-column label="区域" align="center" prop="areaNameStr"/>
      <el-table-column label="接警数量" align="center" prop="areaNameNum"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div id="myChart"></div>

  </div>
</template>

<script>
  import {analysisStatistics} from "@/api/frontierEvent/event";
  import echarts from "echarts";

  export default {
    name: "analysisStatistics",
    components: {},
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 船舶信息表格数据
        shipList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 案件来源字典
        evtTypeOptions: [],
        dateCycleOptions: [],
        // 管辖区字典
        areaNameOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          areaName: undefined,
          createTimeBegin: undefined,
          createTimeEnd: undefined,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
      this.getDicts("evt_violation_type").then(response => {
        this.evtTypeOptions = response.data;
      });
      this.getDicts("date_cycle").then(response => {
        this.dateCycleOptions = response.data;
      });
      this.getDicts("evt_area").then(response => {
        this.areaNameOptions = response.data;
      });
    },
    methods: {
      // 管辖区字典翻译
      evtTypeRateFormat(row, column) {
        return row.evtTypeRate + "%";
      },
      /** 查询船舶信息列表 */
      getList() {
        this.loading = true;
        analysisStatistics(this.queryParams).then(response => {
          this.shipList = response.rows;
          this.total = response.total;
          this.loading = false;

          let nameList = [];
          let dataList = [];
          for (var i = 0; i < response.rows.length; i++) {
            nameList.push(response.rows[i].areaNameStr);
            dataList.push(response.rows[i].areaNameNum);
          }

          // 实例化echarts对象
          let myChartDrawer = echarts.init(document.getElementById('myChart'))

          // 绘制条形图
          var option = {
            backgroundColor: '#0C2E59',
            color: ['#91c7ae'],
            tooltip: {
              trigger: 'axis',
              axisPointer: {
                type: 'line'
              }
            },
            title: {
              text: '统计分析',
              top: 5,
              left: 'center',
              textStyle: {
                color: '#F5F6F8'
              }
            },
            legend: {
              data: ['接警数量'],
              top: 30,
              textStyle: {
                color: '#F5F6F8'
              }
            },
            // X轴
            xAxis: {
              data: nameList,
              axisLabel: {
                interval: 0,
                rotate: 40
              },
              axisLine: {
                lineStyle: {
                  color: '#F5F6F8'
                }
              }
            },
            // Y轴
            yAxis: {
              axisLine: {
                lineStyle: {
                  color: '#F5F6F8'
                }
              }
            },
            // 数据
            series: [
              {
                name: '接警数量',
                type: 'bar',
                data: dataList,
                barWidth: 30,
                itemStyle: {
                  normal: {
                    color: '#5AC4B9'
                  }
                }
              }
            ]
          };

          myChartDrawer.setOption(option);
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      }
    }
  };
</script>

<style>
  #myChart {
    width: 70%;
    min-height: 400px;
    clear: both;
    box-sizing: border-box;
    margin: 80px auto;
  }
</style>
